import vue from 'vue'
import vuerouter from 'vue-router'

vue.use(vuerouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: ()=>import('../views/Login.vue')
},
    {
        path: '/',
        component: () => import( '../views/Home.vue'),
        children: [
            {
                path: '/dashboard',
                component: () => import('../components/Dashboard.vue'),
                meta: {requireAuth: false}
            },
            {
                path: '/pwdsetting',
                component: () => import('../views/PwdSetting.vue'),
                meta: {requireAuth: false}
            },
            {
                path: '/transfer',
                component: () => import('../views/Transfer.vue'),
                meta: {requireAuth: false}
            },
            {
                //银证转账查询
                path: '/transferquery',
                component: () => import( '../views/TransferQuery.vue'),
                meta: {requireAuth: false}
            },
            {
                path: '/orderquery',
                component: () => import('../views/OrderQuery.vue'),
                meta: {requireAuth: false}
            },{
               path:'/hisorderquery',
                component:()=> import('../views/HisOrderQuery.vue'),
                meta:{requireAuth:false}
            },
            {
                //历史成交
                path: '/histradequery',
                component: () => import( '../views/HisTradeQuery.vue'),
                meta: {requireAuth: false}
            },
            {
                path:'/buy',
                component:()=>import('../views/Buy.vue'),
                memet:{requireAuth:false}
            },
            {
                //委卖
                path: '/sell',
                component: () => import('../views/Sell.vue'),
                meta: {requireAuth: false}
            },


        ]
    },
    {
        path: '/404',
        name: '404',
        component: ()=>import('../views/404.vue')
    },{
       path:'*',
        redirect:'/404'
    }
]

const router = new vuerouter({
  mode: 'history',
  base: process.env.base_url,
  routes
})
//路由拦截
//这里用来做出权限校验的
router.beforeEach((to,from,next)=>{
    if (to.meta.requireAuth){
        if (Boolean(sessionStorage.getItem('uid'))){
            next();
        }else{
            next({
                path:'/'
            })
        }
    }else{
        next();
    }
})

export default router
